var fileReader = (function() {
    if (!window.FileReader) {
        return;
    }
    var rFilter = /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\/x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\-portable\-graymap|image\/x\-portable\-pixmap|image\/x\-rgb|image\/x\-xbitmap|image\/x\-xpixmap|image\/x\-xwindowdump)$/i;

    function f() {
        this.fReader = new FileReader();
        this.target = null;
    }
    f.prototype.init = function(t, callback) {
        if (arguments.length !== 2) {
            return;
        }

        this.target = document.querySelector(t);

        this.target.onchange = this.loadImageFile.bind(this);
        this.fReader.onload = function() {
            var d = arguments[0].target.result;
            callback.call(this, d);
        }.bind(this);
    }
    f.prototype.loadImageFile = function() {
        var oFile = this.target.files[0];
        if (!rFilter.test(oFile.type)) {
            alert("请选择正确的图片格式！");
        } else {
            this.fReader.readAsDataURL(oFile);
        }
    }

    return f;
})();
